import { User } from "../../../../modeal/user.js"
const user = new User()
Page({
  data: {
    coupons: {},
    checked: false,
    selectedCoupon: {}, //选中的优惠券
  },
  onLoad: function () {

  },
  onReady () {
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    let coupons = prevPage.data.canUseCoupon
    this.setData({ coupons })

  },

  clickRadio (e) {
    let checked = e.currentTarget.dataset.item;
    this.setData({ checked })
    this.data.checked ? this.setData({ checked: false }) : this.setData({ checked: true })
    this.data.checked ? this.setData({ selectedCoupon: {} }) : ""
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({ selectedCoupon: this.data.selectedCoupon, selectedCouponId: null })
    wx.navigateBack({ delta: 1 })
  },

  // 选择优惠券
  chooseCoupon (e) {
    let coupon = e.currentTarget.dataset.item
    this.setData({ selectedCoupon: coupon, checked: false })
    let selectedCoupon = this.data.selectedCoupon
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({ selectedCoupon, selectedCouponId: selectedCoupon.id })
    wx.navigateBack({ delta: 1 })
  }

})